package com.wqr.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wqr.dao.UserDao;
import com.wqr.pojo.User;
import com.wqr.pojo.UserExample;

@Service
public class UserServiceImp implements UserService{
	@Autowired
	public UserDao userDao;
	
	public List<User> list(User user) throws Exception {
		//UserExample example = new UserExample();
		//List<User> list = userDao.selectByExample(example);
		List<User> list = userDao.selectUserByDIY(user);
		return list;
	}
	public List<User> listAll() throws Exception {
		UserExample example = new UserExample();
		List<User> list = userDao.selectByExample(example);
		return list;
	}
	public int delectUser(Integer userId) throws Exception {
		int a = userDao.deleteByPrimaryKey(userId);
		if(a > 0) {
			return 1;
		}else {
			return 0;
		}
	}
	public int insertUser(User user) throws Exception {
		int a = userDao.insertSelective(user);
		if(a > 0) {
			return 1;
		}else {
			return 0;
		}
	}
	public int updateUser(User user) throws Exception {
		int a = userDao.updateByPrimaryKeySelective(user);
		if(a > 0) {
			return 1;
		}else {
			return 0;
		}
	}

	public List<User> selectUser(User user) throws Exception {
		//List<User> list = userDao.selectByWhere(user);
		return null;
	}

	public User selectByPrimaryKey(Integer userId) throws Exception {
		User list = userDao.selectByPrimaryKey(userId);
		return list;
	}
	public List<User> selectUserByDIY(User user) throws Exception {
		List<User> list = userDao.selectUserByDIY(user);
		return list;
	}
	public User selectUserByLoginId(Integer loginId) throws Exception {
		User list = userDao.selectByLoginId(loginId);
		return list;
	}


}
